package mr.fileToDb;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

/**
 * @Description
 * @author 闫陆新
 * @邮箱 yanluxin522@126.com
 * @Date 2017年5月10日 下午3:29:59
 *
 */

public class SceneKpiMain extends Configured implements Tool {
	public static void main(String[] args) throws Exception {
		ToolRunner.run(new SceneKpiMain(), args);
	}

	@Override
	public int run(String[] args) throws Exception {
		Configuration conf = new Configuration();
		Job job;
		try {
			conf.set("tableconf", "scene.conf");
			conf.set("confpath", "E:\\lte\\libs\\");
			conf.set("libpath", "E:\\lte\\libs\\");
			job = Job.getInstance(conf, "user_kpisum_d");
			//命令行运行
			job.setJarByClass(SceneKpiMain.class);

			job.setMapperClass(SceneKpiMapper.class);

			job.setReducerClass(SceneKpiReducer.class);

			job.setMapOutputKeyClass(Text.class);
			job.setMapOutputValueClass(EsbMRBean.class);

			job.setOutputKeyClass(CollectorWritable.class);
			job.setOutputValueClass(CollectorWritable.class);
			job.setInputFormatClass(TextInputFormat.class);
			//加载jar包
			job.addArchiveToClassPath(new Path("E:\\lte\\libs\\ojdbc5.jar"));
			//表字段配置
			job.addCacheFile(new Path("E:\\lte\\libs\\table.conf").toUri());
			//数据库输出
			job.setOutputFormatClass(OracleDBOutputFormat.class);
			//Reduce个数
			job.setNumReduceTasks(20);
			job.setMaxMapAttempts(20);
			job.setMaxReduceAttempts(20);
			//修改map任务读取文件大小
			//FileInputFormat.setMinInputSplitSize(job, 1024*1024*512);
			FileInputFormat.addInputPath(job, new Path("E:\\lte\\f2\\3"));
			FileOutputFormat.setOutputPath(job, new Path("E:\\lte\\f2\\4"));

			try {
				System.exit(job.waitForCompletion(true) ? 0 : 1);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return 0;
	}
}